// 构造节点
function Node(val)
{
  this.val = val;
  this.next = null;
}

// 链表
function llist() {
  this.head = new Node("head");
  this.find = find;
  this.insert = insert;
//   this.remove = remove;
  this.display = display;
}

function find(itemval){
    let currentNode = this.head
    while(currentNode.val!==itemval){
        currentNode = currentNode.next
    }
    return currentNode

} 

// function insert(newitemval,itemval){
//     var newitem = Node(newitemval)
//     var curretitem = this.find(itemval)
//     newitem.next = curretitem.next 
//     curretitem.next  = newitem

// }
function insert ( newElement , item ) {
    let newNode = new Node( newElement );
    let currNode = this.find( item );
    newNode.next = currNode.next;
    currNode.next = newNode;
}



function display () {
    let currNode = this.head;
    while ( !(currNode.next == null) ){
        console.log( currNode.next.element );
        currNode = currNode.next;
    }
}

let fruits = new llist();

fruits.insert('Apple' , 'head');
fruits.insert('Banana' , 'Apple');
fruits.insert('Pear' , 'Banana');

console.log(fruits.display()); 

